package org.cainiao.basic.generics.wildcard;

import org.cainiao.basic.generics.Generics;

public class GenericsUse {

    public static void main(String[] args) {
        Generics<Number> ng = new Generics<>();
        Generics<Integer> ig = new Generics<>();

        useExtendsNumberGenerics(ng);
        useExtendsNumberGenerics(ig);

        useSuperIntegerGenerics(ng);
        useSuperIntegerGenerics(ig);
    }

    public static void useExtendsNumberGenerics(Generics<? extends Number> numberGenerics) {
        Number a = numberGenerics.getT();
        // 编译报错：Integer b = numberGenerics.getT();
        Number i = 5;
        // 编译报错：numberGenerics.setT(i);
    }

    public static void useSuperIntegerGenerics(Generics<? super Integer> integerGenerics) {
        // 编译报错：Number a = integerGenerics.getT();
        Integer i = 5;
        integerGenerics.setT(i);
        Number n = 6;
        // 编译报错：integerGenerics.setT(n);
    }

}
